<?php


namespace app\api\controller;


use app\admin\model\BrandBusiness;
use think\Request;

class Brand extends Base
{
    public function getBrandLogo(){
        $res = [];

        $brand = new \app\admin\model\Brand();
        $where['status'] = 1;
        $list = $brand->getAll($where);
        if($list == null){
            $res['data']['code'] = 0;
            $res['data']['msg'] = '获取失败';
        }else{
            $res['data']['code'] = 1;
            $res['data']['msg'] = '获取成功';
            $res['data']['list'] = $list;
        }
        $res['status'] = 200;
        echo json_encode($res);
    }

    public function getBrandInfo(Request $request){
        $res = [];
        $data = $request->post();
        if(!isset($data['id'])){
            $res['status'] = 400;
            echo json_encode($res);die;
        }

        $brand = new \app\admin\model\Brand();
        $where['id'] = $data['id'];
        $rs = $brand->getOne($where);
        $brandBusiness = new BrandBusiness();
        $businessWhere['brand_id'] = $rs['id'];
        $rs['business'] = $brandBusiness->getAll($businessWhere);

        if($rs == null){
            $res['data']['code'] = 0;
            $res['data']['msg'] = '获取失败';
        }else{
            $res['data']['code'] = 1;
            $res['data']['msg'] = '获取成功';
            $res['data']['list'] = $rs;
        }
        $res['status'] = 200;
        echo json_encode($res);
    }
}